﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Web.Configuration;

public partial class Najava : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnNajava_Click(object sender, EventArgs e)
    {

        string connectionString = WebConfigurationManager.ConnectionStrings["BankaDB"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(connectionString);
        
        
        using (conn)
        {
            conn.Open();
            OleDbCommand cmd = new OleDbCommand("SELECT Password FROM Player WHERE Username=@username", conn);
            cmd.Parameters.AddWithValue("@username", txtUserName.Text);
            OleDbDataReader rd = cmd.ExecuteReader();

            //If there are no rows returned Exception is thrown
            rd.Read();

            if (MySecurity.Program.IsValidPassword(txtUserName.Text, txtPassword.Text,rd["Password"].ToString()))
            {
                Session["najava"] = txtUserName.Text;
                Session.Timeout = 5;
                Response.Redirect ("~/Demo.aspx");
            }


        }


    }
    protected void btnRegistracija_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Registracija.aspx");
    }
}